﻿

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using MySql.Data.MySqlClient;

public class DAL_tbl_currency_master
{
    public DAL_tbl_currency_master()
    {

    }



    public List<tbl_currency_master> select(String CURRENCY_ID)
    {
        List<tbl_currency_master> list = new List<tbl_currency_master>();
        MySqlCommand cmd = new MySqlCommand();
        cmd.CommandText = "Select CURRENCY_ID,CURRENCY_NAME,CURRENCY_SYMBOL,IS_ACTIVE,CREATED_BY,CEATED_DATE,UPDATED_BY,UPDATED_DATE from tbl_currency_master where CURRENCY_ID=@CURRENCY_ID";
        cmd.Parameters.AddWithValue("@CURRENCY_ID", CURRENCY_ID);
        DataTable dt = DBUtil.ExecuteDataTable(cmd);
        foreach (DataRow dr in dt.Rows)
        {
            list.Add(new tbl_currency_master()
            {
                CURRENCY_ID = dr["CURRENCY_ID"].ToString(),
                CURRENCY_NAME = dr["CURRENCY_NAME"].ToString(),
                CURRENCY_SYMBOL = dr["CURRENCY_SYMBOL"].ToString(),
                IS_ACTIVE = Convert.ToBoolean(dr["IS_ACTIVE"]),
                CREATED_BY = dr["CREATED_BY"].ToString(),
                CEATED_DATE = dr["CEATED_DATE"].toDateTimeWithoutError(),
                UPDATED_BY = dr["UPDATED_BY"].ToString(),
                UPDATED_DATE = dr["UPDATED_DATE"].toDateTimeWithoutError()
            });
        }

        return list;
    }



    public List<tbl_currency_master> selectAll()
    {
        List<tbl_currency_master> list = new List<tbl_currency_master>();
        MySqlCommand cmd = new MySqlCommand();
        cmd.CommandText = "Select CURRENCY_ID,CURRENCY_NAME,CURRENCY_SYMBOL,IS_ACTIVE,CREATED_BY,CEATED_DATE,UPDATED_BY,UPDATED_DATE from tbl_currency_master Order By CURRENCY_ID";

        DataTable dt = DBUtil.ExecuteDataTable(cmd);
        foreach (DataRow dr in dt.Rows)
        {
            list.Add(new tbl_currency_master()
            {
                CURRENCY_ID = dr["CURRENCY_ID"].ToString(),
                CURRENCY_NAME = dr["CURRENCY_NAME"].ToString(),
                CURRENCY_SYMBOL = dr["CURRENCY_SYMBOL"].ToString(),
                IS_ACTIVE = Convert.ToBoolean(dr["IS_ACTIVE"]),
                CREATED_BY = dr["CREATED_BY"].ToString(),
                CEATED_DATE = dr["CEATED_DATE"].toDateTimeWithoutError(),
                UPDATED_BY = dr["UPDATED_BY"].ToString(),
                UPDATED_DATE = dr["UPDATED_DATE"].toDateTimeWithoutError()
            });
        }

        return list;
    }



    public int insert(String CURRENCY_NAME, String CURRENCY_SYMBOL, bool IS_ACTIVE, String CREATED_BY, DateTime CEATED_DATE)
    {
        int i = 0;
        string sql = @"Insert into tbl_currency_master(CURRENCY_NAME, CURRENCY_SYMBOL, IS_ACTIVE, CREATED_BY, CEATED_DATE)
                        values(@CURRENCY_NAME, @CURRENCY_SYMBOL, @IS_ACTIVE, @CREATED_BY, @CEATED_DATE)";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@CURRENCY_NAME", CURRENCY_NAME);
        cmd.Parameters.AddWithValue("@CURRENCY_SYMBOL", CURRENCY_SYMBOL);
        cmd.Parameters.AddWithValue("@IS_ACTIVE", IS_ACTIVE);
        cmd.Parameters.AddWithValue("@CREATED_BY", CREATED_BY);
        cmd.Parameters.AddWithValue("@CEATED_DATE", CEATED_DATE);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



    public int update(String CURRENCY_ID, String CURRENCY_NAME, String CURRENCY_SYMBOL, bool IS_ACTIVE, String UPDATED_BY, DateTime UPDATED_DATE)
    {
        int i = 0;
        string sql = @"Update tbl_currency_master SET CURRENCY_NAME=@CURRENCY_NAME, CURRENCY_SYMBOL=@CURRENCY_SYMBOL, IS_ACTIVE=@IS_ACTIVE, UPDATED_BY=@UPDATED_BY, UPDATED_DATE=@UPDATED_DATE WHERE CURRENCY_ID=@CURRENCY_ID";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@CURRENCY_ID", CURRENCY_ID);
        cmd.Parameters.AddWithValue("@CURRENCY_NAME", CURRENCY_NAME);
        cmd.Parameters.AddWithValue("@CURRENCY_SYMBOL", CURRENCY_SYMBOL);
        cmd.Parameters.AddWithValue("@IS_ACTIVE", IS_ACTIVE);
        cmd.Parameters.AddWithValue("@UPDATED_BY", UPDATED_BY);
        cmd.Parameters.AddWithValue("@UPDATED_DATE", UPDATED_DATE);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



    public int delete(String CURRENCY_ID)
    {
        int i = 0;
        string sql = "Delete FROM tbl_currency_master WHERE CURRENCY_ID=@CURRENCY_ID";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@CURRENCY_ID", CURRENCY_ID);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



}